package com.chen.controller;

import com.chen.common.Result;
import com.chen.utils.UploadUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * ClassName: UploadController
 * Package: com.chen.controller
 * Description:
 *
 * @Author 陈俊辉
 * @Create 2024/4/12 0:01
 * @Version 1.0
 */
@RestController
@Validated
@Tag(name = "后台管理-文件上传")
public class UploadController {

    @PostMapping("/upload")
    @Operation(summary = "文件上传")
    public Result upload(
            @Parameter(name = "image") @RequestParam("image")MultipartFile file
    ) throws IOException {
        UploadUtil uploadUtil = new UploadUtil();
        String url = UploadUtil.upload(file);
        return Result.success(url);
    }
}
